package cj.web.sc.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.sc.domain.SCGoodsItems;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SCGoodsItemsDAO{
    @SQL("select * from SCGoodsItems where id=:1")
    SCGoodsItems queryById(int id);
    
    @SQL("INSERT INTO SCGoodsItems (sellerId,categoryId,goodsId,propValueIds,propValueNames,name,orignPrice,discntPrice,inventory,selledCnt,freight,image,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.sellerId,:t.categoryId,:t.goodsId,:t.propValueIds,:t.propValueNames,:t.name,:t.orignPrice,:t.discntPrice,:t.inventory,:t.selledCnt,:t.freight,:t.image,:t.deleteFlag,NOW(),:t.createUser,NOW(),:t.updateUser)")
    void create(@SQLParam("t") SCGoodsItems sCGoodsItems);
	
	@SQL("UPDATE SCGoodsItems SET name=:t.name,image=:t.image,orignPrice=:t.orignPrice,discntPrice=:t.discntPrice,descs=:t.descs,inventory=:t.inventory,updateAt=NOW(),updateUser=:t.updateUser,propValueNames=:t.propValueNames WHERE id=:t.id")
    void update(@SQLParam("t") SCGoodsItems sCGoodsItems);

	@SQL("SELECT * from SCGoodsItems where deleteFlag=1 and goodsId=:t.goodsId #if(:t.name!=''){ and name like '%##(:t.name)%' } ORDER BY stickAt limit :t.start,:t.length")
	List<SCGoodsItems> queryByItemName(@SQLParam("t")SCGoodsItems goodsItems);

	@SQL("SELECT COUNT(0) from SCGoodsItems where deleteFlag=1 and goodsId=:t.goodsId #if(:t.name!=''){ and name like '%##(:t.name)%' }")
	int sizeByItemName(@SQLParam("t")SCGoodsItems goodsItems);

	@SQL("UPDATE SCGoodsItems SET stickAt=NOW() where id=:1")
	void stick(int id);

	@SQL("select MAX(orignPrice) as maxOrignPrice,MIN(orignPrice) as minOrignPrice,MAX(discntPrice) as maxDiscntPrice,MIN(discntPrice) as minDiscntPrice from SCGoodsItems where goodsId=:1")
	List<Map> range(int goodsId);

	@SQL("UPDATE SCGoodsItems SET deleteFlag=0 where goodsId=:1")
	void deleteByGoodsId(int goodsId);

	@SQL("update SCCart set status=0 where goodsItemId=:1")
	void disableCart(int goodsItemId);

	@SQL("update SCCart set status=:2 where goodsItemId in (select a.id from SCGoodsItems a where a.goodsId=:1)")
	void chgCartByGoodsId(int goodsId, int status);

	@SQL("UPDATE SCGoodsItems SET deleteFlag=1 where goodsId=:1")
	void validateByGoodsId(int id);

	@SQL("select count(1) from SCGoodsItems where deleteFlag=1 and goodsId=:1")
	int getItmCntByGoodsId(int goodsId);

	@SQL("UPDATE SCGoodsItems SET image=:2 where goodsId=:1")
	void updateImgByGoodsId(int goodsId, String imagePath);
    
}